package com.feihao.zhou.workTest;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.function.BiConsumer;

public class Test1 {
    public static void main(String[] args) {
        HashMap<Student,String> map = new HashMap<>();
        map.put(new Student("张三",18),"北京海淀");
        map.put(new Student("李四",18),"广东深圳");
        map.put(new Student("王五",20),"湖南衡阳");
        map.put(new Student("小六子",16),"江苏杭州");

        //】遍历1：
        map.forEach(new BiConsumer<Student, String>() {
            @Override
            public void accept(Student student, String s) {
                System.out.println(student +"来自"+ s);
            }
        });

        System.out.println("====================");

        //遍历2：
        Set<Student> key = map.keySet();
        for (Student k : key) {
            System.out.println(k+ "来自" + map.get(k));
        }

        System.out.println("====================");
        //遍历3：
        Set<Map.Entry<Student, String>> entries = map.entrySet();
        for (Map.Entry<Student, String> entry : entries) {
            Student key1 = entry.getKey();
            String value = entry.getValue();
            System.out.println(key1 + "来自" + value);
        }


        System.out.println("====================");
        //遍历4：
        Set<Student> keyStudent = map.keySet();
        Iterator<Student> itStudent = keyStudent.iterator();
        while (itStudent.hasNext()){
            Student student = itStudent.next();
            System.out.println(student + "来自" + map.get(student));
        }
        System.out.println("--------------oooooo-----------------");

        Set<Map.Entry<Student, String>> entries1 = map.entrySet();
        entries1.stream().forEach(System.out::println);
    }
}
